#include "pushbutton.h"
#include <QDebug>
#include "widget.h"
#include "ui_widget.h"

PushButton::PushButton(QWidget *parent):QPushButton(parent)
{

}

void PushButton::enterEvent(QEvent *event)
{
    (void) event;

    static int count = 0;
    count++;
    if(count >= 5){
        count = 0;
        emit dialog();
    }

    //获取父控件的指针
    Widget *base =(Widget*)parentWidget();
    //修改父控件的label
    base->ui->label->setText("你喜欢学习吗？");

    //获取窗口的大小
    int width =base->geometry().width();
    int height = base->geometry().height();

    //生成一个随机的坐标值
    int x = rand() % width;
    int y = rand() % height;

    //移动按钮
    move(x,y);
}
